#include "StdAfx.h"
#include "InGameStateView.h"
#include "viewmanager.h"
#include "../game/InGameState.h"
#include "ExplotionEmitter.h"
#include <math.h>
#include "../kernel.h"

extern Kernel* g_kernel;
#define TIME g_kernel->GetTime()
extern float NextRand();
const float PI = 3.14159265358979323846f;

InGameStateView::InGameStateView(void): IGameStateView()
{ 

    ////    // FIRE
    //Emitter* emt = new Emitter;
    //emt->SpawnRate = 10;
    //emt->MaxAngle = 0.003f;
    //emt->MaxParticles = 10000;
    //emt->LifeSpan = 7000; // 7sec
    //emt->StartColor = Vector3f( 0.9f, 0.01f, 0.01f );
    //emt->EndColor = Vector3f( 0.1f, 0.16f, 0.12f );
    //emt->ColorFadeTime = 0.0267f;
    //emt->StartAlpha = 1.0f;
    //emt->AlphaFadeTime = 60;
    //emt->Jitter = 0.923423f;
    ////emt->WanderRadius = 0.23459f;
    //emt->WanderRadius = 2.23459f;
    //emt->WanderDistance = 0.0013239f;
    //emt->InitVel = Vector2f( 0, -1 );
    //emt->Acceleration = Vector2f( 1.5f, 1.5f );
    //emt->Position = Vector2f( 400, 400 );
    //partMng.m_emitters.push_back( emt );

    //Emitter* emt2 = new Emitter;
    //emt2->SpawnRate = 130;
    //emt2->MaxAngle = 0.003f;
    //emt2->MaxParticles = 100;
    //emt2->LifeSpan = 8000; // 7sec
    //emt2->StartColor = Vector3f( 0.72f, 0.89f, 0.15f );
    //emt2->EndColor = Vector3f( 0.1f, 0.16f, 0.12f );
    //emt2->ColorFadeTime = 0.0267f;
    //emt2->StartAlpha = 0.23f;
    //emt2->AlphaFadeTime = 60;
    //emt2->Jitter = 0.923423f;
    //emt2->WanderRadius = PI;//360.33459f;
    //emt2->WanderDistance = 0.013239f;
    //emt2->InitVel = Vector2f( 1, -1 );
    //emt2->Acceleration = Vector2f( 1.5f, 1.5f );
    //emt2->Position = Vector2f( 400, 400 );
    //partMng.m_emitters.push_back( emt2 );

        //    //crap
    //ExplotionEmitter* emt = new ExplotionEmitter;
    //emt->SpawnRate = 0;
    //emt->MaxAngle = 0.003f;
    //emt->MaxParticles = 150;
    //emt->MaxTotalParticles = 50;
    //emt->LifeSpan = 3000; // 7sec
    //emt->LifeSpanOfEmitter = TIME + 10000; // 12 sec
    //emt->StartColor = Vector3f( 0.451f, 0.40f, 0.13f );
    //emt->EndColor = Vector3f( 0.451f, 0.40f, 0.13f );
    //emt->ColorFadeTime = 0.0267f;
    //emt->StartAlpha = 1.0f;
    //emt->AlphaFadeTime = 60;
    //emt->Jitter = 0.923423f;
    //emt->ParticleSize = 5.0f;
    //g_kernel->GetRenderer()->GetCamera(0)->Shake( 2000, 10 );
    ////emt->WanderRadius = 0.23459f;
    //emt->WanderRadius = 1;//360;//152.23459f;
    //emt->WanderDistance = 0.0013239f;
    //emt->Acceleration = Vector2f( 14.05f, 14.05f );
    //emt->Position = Vector2f( 400, 400 );
    //partMng.m_emitters.push_back( emt );

    //Emitter* emt2 = new Emitter;
    //emt2->SpawnRate = 130;
    //emt2->MaxAngle = 0.003f;
    //emt2->MaxParticles = 1100;
    //emt2->LifeSpan = 8000; // 7sec
    ////emt2->StartColor = Vector3f( 0.72f, 0.89f, 0.15f );
    ////emt2->EndColor = Vector3f( 0.1f, 0.16f, 0.12f );
    //    emt2->StartColor = Vector3f( 0.481f, 0.12f, 0.13f );
    //emt2->EndColor = Vector3f( 0.41f, 0.11f, 0.13f );
    //emt2->ColorFadeTime = 0.0267f;
    //emt2->StartAlpha = 1.0f;
    //emt2->AlphaFadeTime = 60;
    //emt2->Jitter = 0.0923423f;
    //emt2->WanderRadius = PI;//360.33459f;
    //emt2->WanderDistance = 0.013239f;
    //emt2->InitVel = Vector2f( 1, -1 );
    //emt2->Acceleration = Vector2f( 1.5f, 1.5f );
    //emt2->Position = Vector2f( 400, 400 );
    //partMng.m_emitters.push_back( emt2 );


    
}

InGameStateView::~InGameStateView(void)
{
}

/** Register the ingame state */
void InGameStateView::RegisterState( IGameState* g )
{
    m_inGameState = static_cast<InGameState*>( g );
    m_weatherView.Set( &m_inGameState->m_weather );
}


/** Load a new Scene */
void InGameStateView::LoadScene(const std::string &file )
{
    if ( sceneMng.LoadScene(file) )
        g_kernel->LPrintf("Failed to load map!");
    else {
        // a loaded scene will create the player
        hud.ActivateFor( EntityManager::GetInstance()->GetPlayer() );
    }
}

/** Render this view */
void InGameStateView::Render( IRender *renderer, ICamera* cam )
{
    // Draw the map
    sceneMng.Draw( renderer, cam );
    
    // draw the entities
    ViewManager::GetInstance()->Update( renderer, cam );
    // draw weather effects
    m_weatherView.Render( renderer, cam );

    partMng.Update( g_kernel->GetFrameTime() );
    partMng.Render( renderer, cam );
    // draw the HUD
    hud.DrawHUD( renderer, cam );
} 
